Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only output "No resources found." for human readable printers #40551

Conversation

juanvallejo
Copy link
Contributor

Release note:

release note none

This patch removes the message No resources found (currently printed through stderr) when printing through a generic / non-human-readable printer (json, yaml, jsonpath, custom-columns).

Before*

$ kubectl get pods -o json
No resources found.
{
    "apiVersion": "v1",
    "items": [],
    "kind": "List",
    "metadata": {},
    "resourceVersion": "",
    "selfLink": ""
}

After

$ kubectl get pods -o json
{
    "apiVersion": "v1",
    "items": [],
    "kind": "List",
    "metadata": {},
    "resourceVersion": "",
    "selfLink": ""
}

cc @fabianofranz @stevekuznetsov

@k8s-ci-robot
Copy link
Contributor

Hi @juanvallejo. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with @k8s-bot ok to test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jan 26, 2017
@k8s-reviewable
Copy link

This change is Reviewable

@k8s-github-robot k8s-github-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Jan 26, 2017
@smarterclayton
Copy link
Contributor

@k8s-bot ok to test

@smarterclayton
Copy link
Contributor

Add a test for this behavior to test-cmd

@fabianofranz
Copy link
Contributor

@kubernetes/sig-cli-pr-reviews

@k8s-github-robot k8s-github-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jan 27, 2017
local message=$1
local match=$2

if [[ $(echo "$message" | grep "$match") ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if ! grep -q "${match}" <<<"${message}"; then
    # message does not contain match
fi

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I trust your bash knowledge, somehow the original solution seems more readable to me bash scripting ignorant ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original solution is bad for a large number of reasons. The command-line output of grep is not necessarily stable. if grep finds nothing on your system and in 2017, it doesn't output anything. Tomorrow, someone pushes a change that says "No matches found" (sound familiar? :) ) and suddenly the original check breaks.

The bash if statement is meant to check for return codes of commands (for example, in the original implementation it is checking for the return code of the [[ command). grep, being a well-formed program, will always return 0 if and only if it succeeded, and will return non-zero otherwise. It is always better to use if program rather than spawning a subshell, capturing the output, relying on the hidden default behavior of [[ with strings (that is different with [, by the way)...

@soltysh
Copy link
Contributor

soltysh commented Jan 27, 2017

LGTM, please squash.

@juanvallejo juanvallejo force-pushed the jvallejo/only-output-no-resources-found-for-human-readable-printer branch 2 times, most recently from eb24f9d to 7b808ad Compare January 27, 2017 18:10
local message=$1
local match=$2

if echo "$message" | grep "$match" 2>&1>/dev/null; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grep -q not redirect

@juanvallejo juanvallejo force-pushed the jvallejo/only-output-no-resources-found-for-human-readable-printer branch from 7b808ad to 5ec2a4c Compare January 27, 2017 18:30
@k8s-ci-robot
Copy link
Contributor

@juanvallejo: The following test(s) failed:

Test name Commit Details Rerun command
Jenkins kops AWS e2e 7b808ad link @k8s-bot kops aws e2e test this

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@juanvallejo
Copy link
Contributor Author

@soltysh

LGTM, please squash.

Thanks, done!

@fabianofranz fabianofranz added release-note-none Denotes a PR that doesn't merit a release note. and removed release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Jan 30, 2017
@fabianofranz fabianofranz self-assigned this Jan 30, 2017
@fabianofranz
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 30, 2017
@fabianofranz
Copy link
Contributor

/approve

1 similar comment
@eparis
Copy link
Contributor

eparis commented Jan 30, 2017

/approve

@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

The following people have approved this PR: eparis, fabianofranz

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 30, 2017
@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 40691, 40551, 40683, 40700, 40702)

@k8s-github-robot k8s-github-robot merged commit 25de8ef into kubernetes:master Jan 31, 2017
@juanvallejo juanvallejo deleted the jvallejo/only-output-no-resources-found-for-human-readable-printer branch January 31, 2017 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants